package files_controller_with_factory;
import java.io.*;
import org.apache.log4j.Logger;

public class MkdirCommandExecutor implements ICommandExecutor{
	private static final Logger logger = Logger.getLogger(CopyCommandExecutor.class);  
	
	public void execute(String string){
		String[] str_mas = string.split(" ");
		String path = str_mas[1];
		File path_f = new File(path);
		if(!path_f.exists()){
			logger.warn("Directory not found: " + path);
			//System.out.println("Directory not found: " + path);
			return;
		}
		String name = str_mas[2];
		String sum = path.concat("\\").concat(name);
		File creator = new File(sum);
		Boolean detector=false;
		try{
			detector=creator.mkdir();
			if(detector==true)  logger.info("Directory was created!");
				//System.out.println("Directory was created!");
			else
				logger.warn("Buddy, there is some problem..");
				//System.out.println("Buddy, there is some problem..");
		}catch(Exception e){
			logger.error("Error", e);
			//System.out.println("Unfortunately you have exception:");
			//e.printStackTrace();
		}
	}
	
	private static MkdirCommandExecutor instance;	
	private MkdirCommandExecutor(){		
	}
	public static ICommandExecutor getInstance(){
		if(instance==null){
			instance = new MkdirCommandExecutor();
		}
		return instance;
	}
}
